package com.jokerku.lottery.interfaces;

import com.alibaba.fastjson.JSON;
import com.jokerku.lottery.interfaces.idempotent.annotation.Lock;
import com.jokerku.lottery.interfaces.vo.IdempotentVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @Author: guzq
 * @CreateTime: 2022/11/06 18:01
 * @Description: 幂等controller
 * @Version: 1.0
 */
@RestController
@RequestMapping("/idempotent")
public class IdempotentController {

    private final Logger logger = LoggerFactory.getLogger(IdempotentController.class);

    @PostMapping("/add")
    @Lock(value = "#idempotentVO.name")
    public String add(String uuid, @RequestBody IdempotentVO idempotentVO) throws InterruptedException {
//        logger.info("请求处理中 uuid:{}, vo:{}",uuid, JSON.toJSONString(idempotentVO));
        TimeUnit.SECONDS.sleep(1);
        logger.info("请求处理完成");
        return "success";
    }
}
